<?

//Initiate Authenticate
SecurityRedirect ();

//initiate Vars 
define("PRIMARY_KEY","skada");
$KEY[]         = array("PRIMARY_KEY"=>PRIMARY_KEY);
$FileName      = "ais_report_vcr.php";
$FileTemplate  = "ais_report_vcr_list.html";
$TableName     = "ais_memorial";
$SubHeaderTitle= "Report Cash/Bank - Voucher";
$PageSize      = 10 ;
$HTMLGridList  = "ToolGrid";
//************ FORM ACTION **************
	if (GetParam("Action","")=="Delete") {
		DeleteRecord ("txtCheck",$PageSize);
	}

//Initiate Database Table For Search;
$FNama   = GetParam("vcrSearch","");
$FCode   = GetParam("vcrCodeSearch","");
$FOffice = GetParam("office","");

//******* DATABASE FORM QUERY ***********
$SQL      = "SELECT DISTINCT nobkt, debnam, kdbank, kdcash, IF(kdbank='Bank','Bank','Cash') as form, IF(SUBSTRING(nobkt,1,1)='T','Terima','Bayar') as MType FROM `$TableName`";
$SQLCount = "SELECT count(*) FROM `$TableName` ";
$WHERE    = "(nobkt like ('BB%') OR nobkt like ('BK%') OR nobkt like ('TB%') OR nobkt like ('TK%')) ";
if (GetParam("office","")) $WHERE   .= "AND ktrasl='".GetParam("office","")."' ";

if ($FNama)
	if (strlen($WHERE)) $WHERE .= " AND "." debnam like '".$FNama."%'";
	else $WHERE .= " debnam like '".$FNama."%'";

if ($FCode)
	if (strlen($WHERE)) $WHERE .= " AND "." nobkt like '".$FCode."%'";
	else $WHERE .= " nobkt like '".$FCode."%'";

	if (strlen($WHERE))	$WHERE = " WHERE ".$WHERE;
	else $WHERE = " WHERE 1";

$SQL = $SQL.$WHERE;
$SQLCount = $SQLCount.$WHERE;
$SQL = $SQL." ORDER BY nobkt";

//Select Department
$SQLOffice = "SELECT * FROM tblkantor";

//******* SHOW FORM CONTENT *********
$PageNum = 1;
$RecCnt = $DBConnection->dbc->get_var($SQLCount);

if (GetParam("PageNum","")) $PageNum  = GetParam("PageNum","");

$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate($MOD_TEMPLATE_DIR."/".$FileTemplate);
$TBS->MergeBlock("bln",$KEY);
$TBS->MergeBlock("blg",$DBMysql,$SQL,$PageSize,$PageNum,$RecCnt);
$TBS->MergeBlock("officeformblk",$DBMysql,$SQLOffice);
$TBS->MergeNavigationBar('nv',array('size'=>10,'pos'=>'centred'),$PageNum,$RecCnt,$PageSize) ; 
$TBS->Show();


function DeleteRecord ($sequence_name,$PageSize) {
	global $DBConnection,$FileName,$TableName;	
	for ($x=1;$x<=$PageSize;$x++) {				
		if (GetParam($sequence_name.$x,""))	{
			$DBConnection->Delete("$TableName",$sequence_name.$x);
	    }
	}
	header("Location: $FileName");
	exit;	
}

?>